/*
 * ===========================================================================================
 * = COPYRIGHT
 *          PAX Computer Technology (Shenzhen) Co., Ltd. PROPRIETARY INFORMATION
 *   This software is supplied under the terms of a license agreement or nondisclosure
 *   agreement with PAX Computer Technology (Shenzhen) Co., Ltd. and may not be copied or
 *   disclosed except in accordance with the terms in that agreement.
 *     Copyright (C) 2023 PAX Computer Technology (Shenzhen) Co., Ltd. All rights reserved.
 * ===========================================================================================
 */

import 'package:flutter/material.dart';
import 'package:pos_link/auto_data_source/auto_data_source_common.dart';
import 'package:pos_link/auto_data_source/auto_payload_request_data_source.dart';
import 'package:pos_link/auto_data_source/auto_payload_response_data_source.dart';
import 'package:pos_link/auto_pigeon/poslink_sdk_payload.dart';
import 'package:pos_link/model/response_db.dart';
import 'comm_setting_view_model.dart';

class PayloadViewModel extends ChangeNotifier {
  Future startPayload(ResponseDataBase responseDataBase, List<Map> dataSource) async {
    POSLinkPayloadApi PayloadApi = POSLinkPayloadApi();

    /// command
    Map cmdData = dataSource.first;
    switch (cmdData[kValue]) {
      case PayloadCommand.PayloadRequest:

        /// 获取请求数据
        PayloadPayloadRequest req = PayloadReqData.formPayloadRequest(dataSource);

        /// 交易
        PayloadPayloadResponse rsp = await PayloadApi.payload(req);

        /// 响应数据更新到UI
        PayloadRspData.parseRspPayloadPayloadResponse(rsp, responseDataBase.payloadData);
        break;
      default:
        throw Exception('undefined function');
      //break;
    }
  }
}
